using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Grpc.Core;
using Microsoft.Extensions.Logging;
using Stee.Cap8.Service;

namespace SampleGrpcService
{
    public class GreeterService : Greeter.GreeterBase
    {
        private readonly ILogger<GreeterService> _logger;
        public GreeterService(ILogger<GreeterService> logger)
        {
            _logger = logger;
        }

        public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
        {
            var user = GrpcServiceContext.GetUser(context);
            var requestID = GrpcServiceContext.GetRequestID(context);
            var sessionID = GrpcServiceContext.GetSessionID(context);
            return Task.FromResult(new HelloReply
            {
                Message = $"Hello {request.Name}. RequestID= {requestID}." +
                $" SessionID= {sessionID}, User = {user?.Identity?.Name}"
            });
        }
    }
}
